package com.excellent.system.controller;

import java.util.List;

import com.excellent.common.core.domain.entity.SysUser;
import com.excellent.system.domain.SysStuTest;
import com.excellent.system.domain.SysUserGroupInterview;
import com.excellent.system.service.ISysUserGroupService;
import com.excellent.system.service.ISysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.excellent.common.annotation.Log;
import com.excellent.common.enums.BusinessType;
import com.excellent.system.domain.SysStuBase;
import com.excellent.system.service.ISysStuBaseService;
import com.excellent.common.core.controller.BaseController;
import com.excellent.common.core.domain.AjaxResult;
import com.excellent.common.utils.poi.ExcelUtil;
import com.excellent.common.core.page.TableDataInfo;

/**
 * 报名学生基础信息Controller
 *
 * @author excellent
 * @date 2022-05-01
 */
@Controller
@RequestMapping("/system/base")
public class SysStuBaseController extends BaseController
{
    private String prefix = "system/stu/base";

    @Autowired
    private ISysUserGroupService sysUserGroupService;

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    private ISysStuBaseService sysStuBaseService;

    @GetMapping()
    public String base()
    {
        return prefix + "/base";
    }

    @GetMapping("interviewStu")
    public String interviewStu()
    {
        return prefix + "/interviewStu";
    }

    /**
     * 修改报名学生基础信息
     */
    @GetMapping("interviewStu/edit/{userId}")
    public String interviewStuEdit(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        mmap.put("SysUser", sysUserService.selectUserById(userId));
        return prefix + "/interviewStuEdit";
    }

    /**
     * 修改保存教师管理
     */
    @Log(title = "教师管理", businessType = BusinessType.UPDATE)
    @PostMapping("/stu/interviewStuEdit")
    @ResponseBody
    public AjaxResult interviewStuEdit(SysUser user)
    {
        SysUserGroupInterview sysUserGroupInterview =new SysUserGroupInterview();
        sysUserGroupInterview.setUserId(user.getUserId().toString());
        sysUserGroupInterview.setGroupInterviewId(user.getgroupInterviewId());
        if(null ==sysUserGroupService.selectSysUserGroupInterviewById(sysUserGroupInterview.getUserId())){
            return toAjax(sysUserGroupService.insertSysUserGroupInterview(sysUserGroupInterview));
        }else{
            return toAjax(sysUserGroupService.updateSysUserGroupInterview(sysUserGroupInterview));
        }

    }
    /**
     * 查询报名学生基础信息列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysStuBase sysStuBase)
    {
        startPage();
        List<SysStuBase> list = sysStuBaseService.selectSysStuBaseList(sysStuBase);
        return getDataTable(list);
    }
    /**
     * 通过公告查询报名学生基础信息列表
     */
    @PostMapping("/noticeList")
    @ResponseBody
    public AjaxResult noticeList(SysStuBase sysStuBase)
    {
        List<SysStuBase> sysStuBases = sysStuBaseService.selectSysStuBaseList(sysStuBase);
        StringBuffer result= new StringBuffer();
        for(int i=0;i<sysStuBases.size();i++){
            result.append("<p>"+sysStuBases.get(i).getStuSno()+","+sysStuBases.get(i).getStuName()+";</p>");
        }
        System.out.println(result);
        return AjaxResult.success(result);
    }
    /**
     * 导出报名学生基础信息列表
     */
    @Log(title = "报名学生基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysStuBase sysStuBase)
    {
        List<SysStuBase> list = sysStuBaseService.selectSysStuBaseList(sysStuBase);
        ExcelUtil<SysStuBase> util = new ExcelUtil<SysStuBase>(SysStuBase.class);
        return util.exportExcel(list, "base");
    }

    /**
     * 新增报名学生基础信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存报名学生基础信息
     */
    @Log(title = "报名学生基础信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysStuBase sysStuBase)
    {
        return toAjax(sysStuBaseService.insertSysStuBase(sysStuBase));
    }

    /**
     * 修改报名学生基础信息
     */
    @GetMapping("/edit/{stuSno}")
    public String edit(@PathVariable("stuSno") String stuSno, ModelMap mmap)
    {
        SysStuBase sysStuBase = sysStuBaseService.selectSysStuBaseById(stuSno);
        mmap.put("sysStuBase", sysStuBase);
        return prefix + "/edit";
    }

    /**
     * 修改保存报名学生基础信息
     */
    @Log(title = "报名学生基础信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysStuBase sysStuBase)
    {
        return toAjax(sysStuBaseService.updateSysStuBase(sysStuBase));
    }

    /**
     * 删除报名学生基础信息
     */
    @Log(title = "报名学生基础信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysStuBaseService.deleteSysStuBaseByIds(ids));
    }
}
